import request from "@/utils/request";
const defaultApi = (apiName) => {
    return {
        list: (params) => request.get(`/${apiName}/list`, { params }),
        simpleList: (params) => request.get(`/${apiName}/simple-list`, { params }),
        page: (params) => request.get(`/${apiName}/page`, { params }),
        read: (id) => request.get(`/${apiName}/get?id=` + id),
        create: (id, data) => request.post(`/${apiName}/create`, data),
        update: (id, data) => request.put(`/${apiName}/update`, data),
        delete: (id) => request.delete(`/${apiName}/delete?id=` + id)
    }
}
export const http = {
    system: {
        tenant: defaultApi('system/tenant'),
        tenantPackage: defaultApi('system/tenant-package'),
    },
    menu: {
        ...defaultApi('system/menu'),
    },
    role: {
        ...defaultApi('system/role'),
        roleList: () => request.get('/system/role/simple-list'),
        getRoleMenus: (roleId) => request.get('/system/permission/list-role-menus?roleId=' + roleId),
        updateRoleMenus: (data) => request.post('/system/permission/assign-role-menu', data)
    },
    user: {
        ...defaultApi('system/user'),
        updateStatus: (data) => request.put('/system/user/update-status', data),
        // 重置密码
        resetPassword: (data) => request.put('/system/user/update-password', data),
        getUserRoles: (userId) => request.get('/system/permission/list-user-roles?userId=' + userId),
        updateUserRoles: (data) => request.post('/system/permission/assign-user-role', data)
    },
    member: {
        ...defaultApi('member/user'),
    },
    policy: {
      ...defaultApi('core/agreement-config')
    },
    wxConfig: {
      ...defaultApi('core/param-config')
    },
    order: {
        page: (params) => request.post(`/core/charging-order/getOrderList`, params),
        read:  (params) => request.get(`/core/charging-order/getOrderDetail`, {params}),
   },
    // 获取租户
    getTenantId: (params) => request.get('/system/tenant/get-id-by-name', { params }),
    login: (data) => request.post('/system/auth/login', {
        rememberMe: true,
        tenantName: "芋道源码",
        ...data
    }),
    getUserInfo: () => request.get('/system/auth/get-permission-info'),
    dictList: (params) => request.get('/system/dict-data/simple-list', { params }),
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/infra/file/upload',
        method: 'post',
        data: formData
    })
}

